<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录页面</title>
<script type="text/javascript"
	src="/ssm-shiro-demo/resources/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
	<div>
		<form id="submitForm" action="cas" method="post">
			用户名： <input type="text" name="userName" value="${userName}"> <br/>
			密    码： <input type="password" name="password" value="">
			<div>
				验证码：<input type="text" onblur="verifyCode1(this)"> <img
					alt="点击刷新" title="点击刷新" src="/ssm-shiro-demo/open/validateCode"
					onclick="getVerifyCode(this)" style="cursor: pointer;">
			</div>
			<button type="button" id="login" onclick="saveSubmit();">登录</button>
			<span>${errorMsg}</span>
		</form>
	</div>
</body>
<script type="text/javascript">

	function saveSubmit(){
		if (verifyCode1) {
			$("#submitForm").submit();
		}
	}
	/**
	 * 验证验证码是否正确
	 */
	function verifyCode1(obj) {
		var code = $(obj).val();
		var flag = false;
		$.ajax({
			url : '/ssm-shiro-demo/verifyCode?code=' + code,
			async : false,
			type : 'get',
			dataType : 'json',
			success : function(result) {
				if (result.state != 1) {
					alert(result.message);
					getVerifyCode($(obj).next("img"));
					$(obj).val("");
				}else{
					flag=true;
				}
			}
		});
		return flag;
	}
	function getVerifyCode(obj) {
		var url = $(obj).attr("src") + "?" + Math.random()
		$(obj).attr("src", url);
	}

</script>
</html>